package com.example.bailin.giftsay.sort.activity;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.example.bailin.giftsay.R;
import com.example.bailin.giftsay.baseclass.BaseActivity;
import com.example.bailin.giftsay.entity.HomeCellEntity;
import com.example.bailin.giftsay.guide.NickNListener;
import com.example.bailin.giftsay.guide.PopupClick;
import com.example.bailin.giftsay.guide.activity.NickNameActivity;
import com.example.bailin.giftsay.guide.activity.WebViewActivity;
import com.example.bailin.giftsay.guide.adapter.SelectionAdapter;
import com.example.bailin.giftsay.sort.LmClickListener;
import com.example.bailin.giftsay.tool.MyApp;
import com.example.bailin.giftsay.tool.NetTool;
import com.example.bailin.giftsay.tool.UrlProvide;

/**
 * Created by bailin on 16/8/27.
 *
 * 分类攻略里品类/风格/对象跳转的二级
 */
public class GLSkipActivity extends BaseActivity implements View.OnClickListener{

    private ListView lv;
    private ImageView ivReturn;
    private TextView tvGlskipTitle;
    private ImageView ivGlSkipPaiXu;

    @Override
    protected int setLayout() {
        return R.layout.activity_glskip;
    }

    @Override
    protected void initView() {
        lv = bindView(R.id.lv_glskip);
        ivReturn = bindView(R.id.iv_glskip_return);
        ivGlSkipPaiXu = bindView(R.id.iv_glskip_paixu);
        tvGlskipTitle = bindView(R.id.tv_glskip_title);
        ivReturn.setOnClickListener(this);
    }

    @Override
    protected void initData() {
        Intent intent = getIntent();
        int id = intent.getIntExtra("id", 0);
        String title = intent.getStringExtra("title");
        tvGlskipTitle.setText(title);
        tool().getData(UrlProvide.GL_SKIP + id + UrlProvide.GL_SKIP1, HomeCellEntity.class, new NetTool.NetInterface<HomeCellEntity>() {
            @Override
            public void onSuccess(final HomeCellEntity homeCellEntity) {
                SelectionAdapter adapter = new SelectionAdapter();
                adapter.setHomeCellEntity(homeCellEntity);
                adapter.setPopupClick(new PopupClick() {
                    @Override
                    public void itemOnClick(int position) {
                        Intent intent = new Intent(MyApp.getContext(), WebViewActivity.class);
                        intent.putExtra("url", homeCellEntity.getData().getItems().get(position).getUrl());
                        startActivity(intent);
                    }
                });

                adapter.setNickNListener(new NickNListener() {
                    @Override
                    public void onClick(int id, String imgUrl, String name) {
                        Intent intent = new Intent(MyApp.getContext(), NickNameActivity.class);
                        intent.putExtra("imgUrl", imgUrl);
                        intent.putExtra("name", name);
                        intent.putExtra("id", id);
                        startActivity(intent);
                    }
                });

                adapter.setLmClickListener(new LmClickListener() {
                    @Override
                    public void onClick(int id, String title) {
                        Intent intent = new Intent(MyApp.getContext(), LmSkipActivity.class);
                        intent.putExtra("id", id);
                        intent.putExtra("title", title);
                        startActivity(intent);
                    }
                });
                lv.setAdapter(adapter);
            }

            @Override
            public void onError(String errorMsg) {

            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_glskip_return:
                finish();
                break;
        }
    }


}
